﻿$(function() {
		   
	//IE6 PNG透明
	$(document).pngFix(); 
	
	if($('.listView').length > 0 || $('.price').length > 0 ){
		cssdropdown.startchrome("main");
	}; 

	//Footer
	$('#footer').height($('body').height()-$('#wrapper').height()-31);
	
	//返回页面顶部按纽跟随
	$('#goTop').click(function(){
		$('html,body').animate({scrollTop: '0px'}, 600);
		return false;
	});
	
	
	//picList
	$('.picList .listCo ul li a.image').each(function(){
		$(this).css('background','url('+$(this).attr('rev')+') no-repeat');
	})
	
	
	$('a.single_image').fancybox({'titleShow':true});
	
	if($('.picList').length > 0){
		$("a[rel=photoGroup]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
		$("a[rel=photoGroup]").hover(function(){
			$(this).parent().find("a.btn").fadeIn("fast");									  
		});
		$("a[rel=photoGroup]").parent().hover(function(){								  
		},function(){
			$(this).find("a.btn").fadeOut("fast");									  
		})
	};
	
	if($('.listView').length > 0){
		$(".subMenu .btn").fancybox({
			'width'				: 430,
			'height'			: 260,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		$("a[rel=photoGroup]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
		
	};
	
	if($('.product').length > 0){		
		$("a[rel=photoGroup]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	};

	if($('.price').length > 0){		
		$("a[rel=photoGroup]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	};
	
	
	if($('.createBtn').length > 0){
		$(".createBtn").fancybox({
			'width'				: 430,
			'height'			: 260,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
	}
	
	if($('.batchupload').length > 0){
		$(".batchupload").fancybox({
			'width'				: 500,
			'height'			: 450,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
	}

	//tab选项卡
	$("a.tabs").click(function () {
		$(this).parent().find("a.current").removeClass("current");
		$(this).addClass("current");
		$("#"+$(this).siblings().attr("rel")).hide();
		//$(this).parent().parent().find(".tabsCo").hide();
		var content_show = $(this).attr("rel");
		$("#"+content_show).show();
		return false;
	});
	
	$(".cate div h3").click(function(){
		if($(this).next("ul").css("display")=="none"){
			$(this).next("ul").css("display","inline");
			$(this).next("br").css("display","block");
		}else{
			$(this).next("ul").css("display","none");	
			$(this).next("br").css("display","none");	
		}
	})
	
	//更改首选清单
	$('#orderList input:checkbox').live('click', function() {
		$('#orderList input:checkbox').attr("checked", false);
		$.getJSON('index.php?m=order&c=index&a=setSelected', {id:$(this).val()});
		$(this).attr("checked", true);
	});

	
})

//点评
function dianping(elem, a, id, modelid) {
	var _font = $(elem).next("."+a);
	$.getJSON('index.php?m=content&c=index&a=ajax_update', {t:a, modelid:modelid, id:id});
	_font.html(parseInt(_font.html())+1);
}
//添加到清单
function addOrder(id) {
	$.getJSON('index.php?m=order&c=order_detail&a=add', {productid:id, ajax:1}, function(data){
		if(data.code == true) {
			$('#msgBox').html("<div class='suc'>"+data.msg+"</div>");
			$('#msgBox').fadeIn("fast");
			setTimeout(function(){$("#msgBox").fadeOut("fast");},800);
		} else {
			$('#msgBox').html("<div class='err'>"+data.msg+"</div>");
			$('#msgBox').fadeIn("fast");
			setTimeout(function(){$("#msgBox").fadeOut("fast");},3000);
		}
		//alert(data.msg);
	});
}
